# -*- coding: iso-8859-2 -*-

import re
import string

from authorshipanalyzer.authorslot import AuthorFiller
from authorshipanalyzer.slot import Slot

class EmailFeaturesFiller(AuthorFiller):
    
    def fill(self, authorslot):
        '''
        Fill a slot:
        - advert
        - signature
        - greetings
        - farewell
        '''
        
        advertCounter = 0.0
        signatureCounter = 0.0
        
        for slot in authorslot.slots:
            
            if authorslot.requotationTypes.has_key(slot.requotationType):
                authorslot.requotationTypes[slot.requotationType] += 1.0
            else:
                authorslot.requotationTypes[slot.requotationType] = 1.0
            
            if slot.hasAdvert:
                advertCounter += 1.0    
                
            if slot.signature:
                signatureCounter += 1.0
                
            if authorslot.greetings.has_key(slot.greeting):
                authorslot.greetings[slot.greeting] += 1.0
            else:
                authorslot.greetings[slot.greeting] = 1.0
                
            if authorslot.farewells.has_key(slot.farewell):
                authorslot.farewells[slot.farewell] += 1.0
            else:
                authorslot.farewells[slot.farewell] = 1.0
                
        divider = float(len(authorslot.slots))
                
        for key, value in authorslot.requotationTypes.items():
            authorslot.requotationTypes[key] = value / divider 
            
        authorslot.advertIndicator = advertCounter / divider 
        authorslot.signature = signatureCounter / divider 
        
        for key, value in authorslot.greetings.items():
            authorslot.greetings[key] = value / divider
            
        for key, value in authorslot.farewells.items():
            authorslot.farewells[key] = value / divider
        


